import { Orders } from '../entity/orders.model';
import * as OrdersActions from '../actions/orders.action';

const initOrder=  {
  orderList: [],
}
export function OrdersReducer(state: Orders= initOrder, action: OrdersActions.All){
  switch (action.type) {

    /*** 借款进度
     * 0 退出清空状态
     * */
    case OrdersActions.RESET_ORDER_STORE:
      return initOrder;

    /*** 获取借款进度
     * 1.1 查询用户借款状态和历史记录成功
     * */
    case OrdersActions.GET_USER_ORDERS_SUCCESS:
      return {...state,
        orderList: [...action.payload] || [], // 更新订单
      };

    /*** 获取借款进度
     * 1.2 查询用户借款状态和历史记录为空
     * */
    case OrdersActions.GET_USER_ORDERS_FAILED:
      return initOrder;

    default:
      return state;
  }
}
